// const state =
// {
//     fetchStatus: {}
//     user: {},
//     driveCard: {}
// }

import {combineReducers} from "redux"
const ActionType = require('./actionType');

function fetchStatus(state = {isLoading: false, isSuccess: true}, action) {
    console.log('fetchStatus');
    switch (action.type) {
        case ActionType.FETCH_BEGIN:
            return Object.assign({}, state, {
                isLoading: true
            });
            break;
        case ActionType.FETCH_SUCCESS:
            return Object.assign({}, state, {
                isLoading: false,
                isSuccess: true
            });
            break;
        case ActionType.FETCH_FAIL:
            return Object.assign({}, state, {
                isLoading: false,
                isSuccess: false
            });
            break;
    }
    return state;
}

function user(state = {}, action) {
    console.log('user');
    switch (action.type) {
        case ActionType.UserInfo:
            return Object.assign({}, state, action.data);
            break;
    }
    return state;
}

function driveCard(state = {}, action) {
    console.log('driveCard');
    switch (action.type) {
        case ActionType.DriveCardInfo:
            return Object.assign({}, state, action.data);
            break;
    }
    return state;
}

const reducer = combineReducers({
    fetchStatus,
    user,
    driveCard
});

module.exports = reducer;
